import re
from lxml import etree
import requests


def group_01(json_info, cookie_end, DOMAIN):
    url = f"{DOMAIN}/phis/app/svc/first/soap/create/1?ehrBaseId={json_info}"
    headers = {
        "cookie": f"JSESSIONID={cookie_end}",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"
    }

    dict_group_01 = {"首诊记录": ""}

    response_01 = requests.get(url, headers=headers)
    tree2 = etree.HTML(response_01.text)

    # 查找包含"[全科诊疗记录]"的td标签
    td_elements = tree2.xpath('//td[contains(text(), "[全科诊疗记录]")]')

    if td_elements:
        td_element = td_elements[0]
        # 检查该td元素下是否有span标签
        span_elements = td_element.xpath('./span')

        if span_elements:
            dict_group_01["首诊记录"] = "无首诊记录"
        else:
            dict_group_01["首诊记录"] = "有首诊记录"
    else:
        dict_group_01["首诊记录"] = None
    print(dict_group_01)
    return dict_group_01



if __name__ == '__main__':
    group_01("530008", "3C5359CC9F73BBBAAA9637AB45CBF706", "http://10.216.11.24:8306")
